from typing import List
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.api import deps
from app.models.user_model import User
from app.schemas.user import UserInfo, UserUpdateRequest, UserResponse

router = APIRouter()

@router.get("/me", response_model=UserResponse)
async def read_users_me(
    current_user: User = Depends(deps.get_current_active_user)
):
    """
    获取当前用户信息
    """
    return current_user

@router.put("/me", response_model=UserResponse)
async def update_user_me(
    *,
    db: Session = Depends(deps.get_db),
    user_in: UserUpdateRequest,
    current_user: User = Depends(deps.get_current_active_user),
):
    """
    更新当前用户信息
    """
    if user_in.nickname is not None:
        current_user.nickname = user_in.nickname
    db.add(current_user)
    db.commit()
    db.refresh(current_user)
    return current_user

@router.get("/{user_id}", response_model=UserResponse)
async def read_user_by_id(
    user_id: int,
    db: Session = Depends(deps.get_db),
):
    """
    通过ID获取用户信息
    """
    user = db.query(User).filter(User.id == user_id).first()
    if user is None:
        raise HTTPException(
            status_code=404,
            detail="User not found"
        )
    return user 